// -----------------------------------------------
// Author:     code34 nicolas_boiteux@yahoo.fr
// Edited by:  Neumatic
// Warcontext: Create an US ammobox on local client side
// -----------------------------------------------

private [
	"_crate",
	"_position",
	"_amountWeapon",
	"_amountAmmo",
	"_refreshTime",
	"_magazines",
	"_autoload"
];

_position = _this select 0;
_autoload = _this select 1;

_crate = "USVehicleBox_EP1" createVehicleLocal _position;

clearWeaponCargo _crate;
clearMagazineCargo _crate;
_crate setPos _position;

wcgarbage = [format ["wcammobox%1", wcammoboxindex], 0.5, _position, "ColorYellow", "ICON", "FDIAGONAL", "Select", 0, "Ammobox", true] call WC_fnc_createmarkerlocal;
wcammoboxindex = wcammoboxindex + 1;

_magazines = [];

_amountweapon = 2;
_amountammo = 20;

_refreshtime = 1800; 
_crate allowDamage false;

while {true} do {
	clearWeaponCargo _crate;
	clearMagazineCargo _crate;

	switch (_autoload) do {
		case "addons": {
			{_crate addWeaponCargo [_x, _amountweapon]} foreach wclistofaddonweapons;
			_magazines = [wclistofaddonweapons] call WC_fnc_enummagazines;
		};

		default {
			{_crate addWeaponCargo [_x, _amountweapon];} foreach wclistofweapons;
			_magazines = [wclistofweapons + ["Throw", "Put"]] call WC_fnc_enummagazines;
		};
	};

	{_crate addMagazineCargo [_x, _amountammo]} foreach _magazines;
	
	sleep _refreshtime;
};